package com.anno.aspectj;

import com.anno.anno.SysLog;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.*;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;

/**
 * @author cyt
 * @create 2020-07-19 15:56
 */

/**
 * 切面类
 *
 * @author cyt
 */
@Aspect
@Component
public class Point {
    /**
     *     @After()
     *     @AfterThrowing
     *     @AfterReturning
     *     @Around
     *     @Before
     *
     */
    @Before("execution(* com.anno.service.Buy.Play(..))")
    public void Before() {
        System.out.println("男孩女都有自己喜欢的事情");
    }


    @Around("execution(* com.anno.service.Buy.Play(..))")
    public void Around(ProceedingJoinPoint point) throws Throwable {
        System.out.println("环绕前.....");
        System.out.println(point);

        /*  得到参数*/

        Object[] args = point.getArgs();
        System.out.println("args=> " + args.toString());

        /*   得到切入点的类型*/

        String kind = point.getKind();
        System.out.println("kind=> " + kind);

        /*     切入点 得到被增强方法的方法签名*/

        MethodSignature methodSignature = (MethodSignature) point.getSignature();


        /*方法签名 到被增强方法的方法*/

        Method method = methodSignature.getMethod();
        System.out.println("method = > " + method);

        /*  方法 名 到被增强方法的方法 上面的注解*/

        SysLog sysLog = method.getAnnotation(SysLog.class);

        System.out.println(sysLog.value());
        Signature signature = point.getSignature();
        String name = signature.getName();
        Class declaringType = signature.getDeclaringType();
        int modifiers = signature.getModifiers();
        String declaringTypeName = signature.getDeclaringTypeName();
        System.out.println("name= > " + name + " declaringType => " + declaringType + " modifiers => " + modifiers + " declaringTypeName => " + modifiers);
        System.out.println("signature=> " + signature);

      /*  得到目标*/

        Object target = point.getTarget();
        System.out.println("target=> " + target);
        System.out.println("环绕后.....");
    }

    /**
     * 定义一个切点
     */
    @Pointcut("execution(* com.anno.service.Buy.Play(..))")
    public void AspectJPoint() {
    }

    @Before("AspectJPoint()")
    public void point1() {
        System.out.println("前置通知");
    }

}
